{{include './header.html'}}
<link rel="stylesheet" href="./css/index.css">
  <div class="container books">
    {{if data.length}}
        {{each data obj}}
          <div>
            <section>
               <img src="./bookimg/{{obj.pic}}" alt="">
              <p class="details">《{{obj.bookname}}》{{obj.author}}</p>
              <p class="num">销量:({{obj.num}})</p>
              <p class="activity">￥{{obj.price*obj.count/10}} <del>￥{{obj.price}}</del>({{obj.count}}折)</p>

              <!-- 加入购物车 -->
              <button class="addcar btn btn-danger" data-id="{{obj.id}}">
                <i class="glyphicon glyphicon-shopping-cart"></i>
                加入购物车
              </button>
            </section>
           
          </div>
        {{/each}}
      {{else}}
        <h1>当前还没有任何的书籍！！请耐心等待~~~</h1>
      {{/if}}
  </div>

  <script>
    if(username=='admin') $('.addcar').hide()
    $('.addcar').click(function(){
      if(username){
        // 把当前这个书籍加入购物车
        $.get('/addcar?id='+this.dataset.id+'&username='+username,data=>{
          alert(data)
        })
      }else{
        // 弹出登录模态框
        $('#myModal').modal('show')
      }
    })
   </script>
   
</body>
</html>